//
//  ThemeDictionaryPicker.swift
//  HeadlineNews
//
//  Created by han on 2019/7/25.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

final class ThemeDictionaryPicker: ThemePicker {
    convenience init<T>(keyPath: String, map: @escaping (Any?) -> [T: AnyObject]?) {
        self.init(v: { map(ThemeManager.value(for: keyPath)) })
    }
    
    convenience init<T>(dicts: [T: AnyObject]...) {
        self.init(v: { ThemeManager.element(for: dicts) })
    }
    
}

extension ThemeDictionaryPicker: ExpressibleByArrayLiteral {
    convenience init(arrayLiteral elements: [String: AnyObject]...) {
        self.init(v: { ThemeManager.element(for: elements) })
    }
}

extension ThemeDictionaryPicker {
    
    class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> [String: AnyObject]?) -> ThemeDictionaryPicker {
        return ThemeDictionaryPicker(v: { map(ThemeManager.value(for: keyPath)) })
    }
    
    class func pickerWithKeyPath(_ keyPath: String, mapAttributes: @escaping (Any?) -> [NSAttributedString.Key: AnyObject]?) -> ThemeDictionaryPicker {
        return ThemeDictionaryPicker(v: { mapAttributes(ThemeManager.value(for: keyPath)) })
    }
    
    class func pickerWithDicts(_ dicts: [[String: AnyObject]]) -> ThemeDictionaryPicker {
        return ThemeDictionaryPicker(v: { ThemeManager.element(for: dicts) })
    }
    
    class func pickerWithAttributes(_ attributes: [[NSAttributedString.Key: AnyObject]]) -> ThemeDictionaryPicker {
        return ThemeDictionaryPicker(v: { ThemeManager.element(for: attributes) })
    }
    
}
